package ui.videos 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	import utils.TextFieldUtil;
	
	/**
	 * ...
	 * @author usual
	 */
	public class TimeText extends MovieClip 
	{
		private var _txtField:TextField;
		public function TimeText() 
		{
			addEventListener(Event.ADDED_TO_STAGE, build);
		}
		
		public function update(playHeadTime:Number):void 
		{
			TextFieldUtil.setText(_txtField, "<timer>" + formatTime(playHeadTime) + "</timer>");
		}
		
		private function build(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, build);
			_txtField = new TextField();
			TextFieldUtil.setText(_txtField, "<timer>00:00</timer>");
			addChild(_txtField);
		}
		private function formatTime(t:int):String
		{
			var s:int = Math.round(t);
			var m:int = 0;
			if (s > 0) {
				while (s > 59) {
					m++;
					s -= 60;
				}
			return String((m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
			} else {
				return "00:00";
			}
		}
	}

}